# !/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: JHC000abc@gmail.com
@file: model_tasks.py
@time: 2024/10/24 18:04 
@desc: 

"""
from sqlalchemy.sql import func
from sqlalchemy import Column, INT, VARCHAR, DateTime, Enum, JSON, CHAR,Text
from db.base_model import Base


class TaskInfo(Base):
    """
    任务表
    """

    __tablename__ = 'task_info'
    id = Column(INT, primary_key=True, autoincrement=True, nullable=False, index=True, unique=True)
    project_id = Column(VARCHAR(5), nullable=False, unique=False, comment="项目ID")
    task_id = Column(CHAR(36), nullable=False, unique=False, comment="任务ID")
    user_id = Column(INT, nullable=False, unique=False, comment="用户id")
    status = Column(Enum("0", "1", "2", "3","4"), nullable=False, default="0", comment="0:初始化 1:运行中 2:成功 3:失败 4:已废弃")
    result = Column(VARCHAR(100), nullable=True, unique=False)
    err = Column(Text, nullable=True, unique=False)
    extra = Column(JSON, nullable=True, comment="附加信息")
    create_time = Column(DateTime, nullable=False, server_default=func.now(), comment="任务提交时间")
    update_time = Column(DateTime, nullable=False, server_default=func.now(), onupdate=func.current_timestamp(),
                         comment="更新时间")
    __table_args__ = {
        'mysql_charset': 'utf8mb4'  # 设置字符集为utf8mb4
    }

STATUS_TASK_INIT = "0"
STATUS_TASK_RUNNING = "1"
STATUS_TASK_SUCCESS = "2"
STATUS_TASK_FAILED = "3"
STATUS_TASK_DISCARD = "4"